package com.taotao.tools.core.bean;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 *
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ObjectUtils {

    /**
     * 严格地判断相等。判断相等前会先检查参数的类型是否一致
     *
     * @param a
     * @param b
     * @return
     * @throws IllegalArgumentException a与b类型不同且a与b类型之间不存在继承关系
     */
    public static boolean equalsStrictly(Object a, Object b) {

        if (!Objects.equals(a.getClass(), b.getClass()) && !a.getClass().isAssignableFrom(b.getClass()) && !b.getClass().isAssignableFrom(a.getClass())) {
            throw new IllegalArgumentException("arg a must have same type with arg b!!");
        }


        return (a == b) || (a != null && a.equals(b));
    }

}
